// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
    const db = cloud.database();
    // console.log(event);
    const {tableName,sort='',skip=0,limit=20,where={},lookup={from:'users',localField:'_openid',foreignField:'_openid',as:'userInfo'}} = event;
    const wxContext = cloud.getWXContext();
    // return 123;
    if(sort && JSON.stringify(sort) != '{}'){
        return db.collection(tableName).aggregate().match(where).sort(sort).skip(skip).limit(limit).lookup(lookup).end();
    }else{
        return db.collection(tableName).aggregate().match(where).skip(skip).limit(limit).lookup(lookup).end();
    }
}